home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directx9_c.chm / directx / code / topinfo.js < prev    next >
Encoding:
Text File  |  2004-09-30  |  10.6 KB  |  524 lines

  1. <![CDATA[
  2. // CTopicInfo: Object consolidating topic info of the topic currently
  3. // being processed. Encapsulates topic info like Standards info,
  4. // Ansi/Unicode info, etc. //at
  5.  
  6. // Here are some display text strings that are used.
  7. var sThis = "This ";
  8. var sAnd = " and ";
  9. var sDef = "is defined in ";
  10. var sDep = "is deprecated in ";
  11. var sPro = "is part of a proposed addition to ";
  12. var sMSE = "is a Microsoft extension to ";
  13. var sNMS = "is an extension to ";
  14.  
  15. // Augment string object with a trim method.
  16. String.prototype.trimsp = function()
  17. {
  18.   return this.replace(/(^\s+)|(\s+$)/g, "");
  19. }
  20.  
  21. function CTopicInfo()
  22. {
  23.   this._bInitialized = false;
  24. }
  25.  
  26. CTopicInfo.prototype.Init = function()
  27. {
  28.   if (this._bInitialized)
  29.     return false;
  30.  
  31.   this._oTopic = null;
  32.   this._nStds = 0;
  33.   this._aStds = null;
  34.   this._oCurStd = null;
  35.   this._oAc = null;
  36.   this._sTLA = "";
  37.   this._sRID = "";
  38.   this._sXRID = "";
  39.   this._sTypeName = "";
  40.   this._sTypeCaption = "";
  41.   this._sError = "";
  42.  
  43.   this._bInitialized = true;
  44.  
  45.   return true;
  46. }
  47.  
  48. CTopicInfo.prototype.ResetInit = function()
  49. {
  50.   this._bInitialized = false;
  51. }
  52.  
  53. CTopicInfo.prototype.SetErrorAndFail = function(sErr)
  54. {
  55.   this._sError = sErr;
  56.   this.ResetInit();
  57.   return false;
  58. }
  59.  
  60. CTopicInfo.prototype.BadTLA = function()
  61. {
  62.   var bError = false;
  63.  
  64.   if (this._sError == "badtla")
  65.     bError = true;
  66.  
  67.   return bError;
  68. }
  69.  
  70. CTopicInfo.prototype.BadStd = function()
  71. {
  72.   var bError = false;
  73.  
  74.   if (this._sError == "badstd")
  75.     bError = true;
  76.  
  77.   return bError;
  78. }
  79.  
  80. CTopicInfo.prototype.BadLogic = function()
  81. {
  82.   var bError = false;
  83.  
  84.   if (this._sError == "badlogic")
  85.     bError = true;
  86.  
  87.   return bError;
  88. }
  89.  
  90. CTopicInfo.prototype.BadXRef = function()
  91. {
  92.   var bError = false;
  93.  
  94.   if (this._sError == "badxref")
  95.     bError = true;
  96.  
  97.   return bError;
  98. }
  99.  
  100. // Return true if there was an error.
  101. CTopicInfo.prototype.WasError = function()
  102. {
  103.   var bError = false;
  104.  
  105.   if (this._sError != "")
  106.     bError = true;
  107.  
  108.   return bError;
  109. }
  110.  
  111. // See if the current page's id is listed in standards.xml.  //at
  112. // Perform some initial one-time setup if it is.
  113. CTopicInfo.prototype.HasInfo = function(oTopicData)
  114. {
  115.   var bFound = false;
  116.   var sID = oTopicData._sID;
  117.   var aStds = null;
  118.   var oDoc = goCtx.GetDocument();
  119.   var oMeta = null;
  120.   var sMetaType = "";
  121.   var sPType = this._sTypeName;
  122.  
  123.   if (!sPType && oDoc)
  124.   {
  125.     sPType = "";
  126.     oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
  127.     if (oMeta)
  128.     {
  129.       sMetaType = oMeta.getAttribute("type");
  130.       if (sMetaType)
  131.       {
  132.           //this is a total hack to handle the one doctype.xml page - petertay
  133.         if (sMetaType=="htmldeclaration")
  134.         {
  135.             sPType = "declaration";
  136.         }
  137.         else
  138.         {
  139.             sPType = sMetaType;
  140.         }
  141.         this._sTypeCaption = sPType;
  142.         this._sTypeName = sPType;
  143.       }
  144.     }
  145.   }
  146.  
  147.   this._sRID = sID;
  148.  
  149.   this._oTopic = goLookup.RetrieveTopicInfo(sID);
  150.   if (this._oTopic)
  151.   {
  152.     // this.ResetInit();
  153.     aStds = this._oTopic.selectNodes("standards/standard");
  154.     this._aStds = aStds;
  155.     if (aStds)
  156.     {
  157.       this._nStds = aStds.length;
  158.       if (this._nStds)
  159.       {
  160.         this._oCurStd = aStds[this._nStds-1];
  161.         bFound = true;
  162.       }
  163.     }
  164.   }
  165.   else
  166.     this._sError = goLookup._error;
  167.  
  168.   return bFound;
  169. }
  170.  
  171. // Return true if no standard applies.
  172. CTopicInfo.prototype.IsNoStd = function()
  173. {
  174.   var bNoStd = false;
  175.   var oStd = null;
  176.  
  177.   if (this._aStds.length)
  178.   {
  179.     oStd = this._aStds[0];
  180.     if (oStd)
  181.       if (oStd.getAttribute("no_standard"))
  182.         bNoStd = true;
  183.   }
  184.  
  185.   return bNoStd;
  186. }
  187.  
  188. // Return current standards countdown.
  189. CTopicInfo.prototype.NumStds = function()
  190. {
  191.   return this._nStds;
  192. }
  193.  
  194. // Get the literal display text for the current standard node.
  195. // Check for bad attribute logic.
  196. CTopicInfo.prototype.GetText = function()
  197. {
  198.   var sRet = "";
  199.   var sVal = "";
  200.   var sTLA = "";
  201.   var sExt = "";
  202.   var bDep = false;
  203.   var bPro = false;
  204.   var sLit = "";
  205.   var sAtt = "";
  206.   var bAtt = false;
  207.   var bOk = true;
  208.   var oDoc = goCtx.GetDocument();
  209.   var oMeta = null;
  210.   var sMetaType = "";
  211.   var sPType = this._sTypeName;
  212.  
  213.   if (!sPType && oDoc)
  214.   {
  215.     sPType = "";
  216.     oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
  217.     if (oMeta)
  218.     {
  219.       sMetaType = oMeta.getAttribute("type");
  220.       if (sMetaType)
  221.       {
  222.         sPType = sMetaType;
  223.         this._sTypeCaption = sPType;
  224.         this._sTypeName = sPType;
  225.       }
  226.     }
  227.   }
  228.  
  229.   // Got a live standard entry--get the attributes.
  230.   sTLA = this._oCurStd.getAttribute("tla");
  231.   sExt = this._oCurStd.getAttribute("extension");
  232.   if (this._oCurStd.getAttribute("deprecated"))
  233.     bDep = true;
  234.   if (this._oCurStd.getAttribute("proposed"))
  235.     bPro = true;
  236.  
  237.   // Check the attribute logic.
  238.   if (!sTLA)
  239.     bOk = false;
  240.   if (bOk && sExt && (bDep || bPro))
  241.     bOk = false;
  242.   if (bOk && bDep && (sExt || bPro))
  243.     bOk = false;
  244.   if (bOk && bPro && (sExt || bDep))
  245.     bOk = false;
  246.  
  247.   // Now assemble the text string based on the attributes.
  248.   if (bOk)
  249.   {
  250.     this._sTLA = sTLA;
  251.     this._oAc = goLookup.RetrieveAcronym(sTLA);
  252.     if (this._oAc)
  253.     {
  254.       bAtt = (sExt || bDep || bPro);
  255.       sAtt = this._oAc.getAttribute("standard");
  256.       if (sAtt && bAtt && (sAtt == "specific"))
  257.       {
  258.         this._sError = "badlogic";
  259.         bOk = false;
  260.       }
  261.       else
  262.       {
  263.         // Assemble the literal text part of the sentence.
  264.         sLit = sDef;
  265.         if (bDep)
  266.           sLit = sDep;
  267.         else if (bPro)
  268.           sLit = sPro;
  269.         else if (sExt == "ms")
  270.           sLit = sMSE;
  271.         else if (sExt == "nonms")
  272.           sLit = sNMS;
  273.       }
  274.     }
  275.     else
  276.     {
  277.       this._sError = "badtla";
  278.       bOk = false;
  279.     }
  280.   }
  281.   else
  282.     this._sError = "badlogic";
  283.  
  284.   if (bOk)
  285.   {
  286.     if (this._nStds == this._aStds.length)
  287.       sRet = sThis + sPType + " " + sLit;
  288.     else
  289.       sRet = " " + sLit;
  290.   }
  291.  
  292.   return sRet;
  293. }
  294.  
  295. // Set the basic type name caption.
  296. CTopicInfo.prototype.SetTypeName = function(sType, sTypeCaption)
  297. {
  298.   var oDoc = goCtx.GetDocument();
  299.   var oMeta = null;
  300.   var sMetaType = "";
  301.  
  302.   this.Init();
  303.  
  304.   if (oDoc)
  305.   {
  306.     oMeta = oDoc.selectSingleNode("/inetsdk:topic/metadata");
  307.     if (oMeta)
  308.     {
  309.       sMetaType = oMeta.getAttribute("type");
  310.       if (sMetaType == sType)
  311.       {
  312.         this._sTypeCaption = sTypeCaption;
  313.         this._sTypeName = sTypeCaption.toLowerCase();
  314.       }
  315.     }
  316.   }
  317. }
  318.  
  319. // Return current page type name. //at
  320. CTopicInfo.prototype.GetTypeName = function()
  321. {
  322.   return this._sTypeName;
  323. }
  324.  
  325. // Return current page type name. //at
  326. CTopicInfo.prototype.GetTypeCaption = function()
  327. {
  328.   return this._sTypeCaption;
  329. }
  330.  
  331. // Lookup the href path to the destination.
  332. CTopicInfo.prototype.GetHREF = function()
  333. {
  334.   var sRet = "";
  335.   var sErr = "";
  336.   var bOk = false;
  337.   var sXrid = "";    //at
  338.   var sXML = "";
  339.   var oTNode = null;
  340.   var oTDom = goCtx._oTDom;
  341.  
  342.   if (this._oAc)
  343.   {
  344.     sXrid = this._oAc.getAttribute("xrid");
  345.     if (sXrid)
  346.     {
  347.       this._sXRID = sXrid;
  348.       sXML = "<xref rid=\"" + sXrid + "\"></xref>";
  349.  
  350.       // Now use "mini-dom" node to load node-xml and get a node.
  351.       oTDom.async = false;
  352.       oTDom.loadXML(sXML);
  353.       oTNode = oTDom.documentElement;
  354.       if (oTNode)
  355.       {
  356.         if (goLookup.LookupByNode(oTNode, goDest))
  357.         {
  358.           sRet = goDest.GetHREF();
  359.           bOk = true;
  360.         }
  361.         else
  362.           sErr = "badxref";
  363.       }
  364.       else
  365.         sErr = "badxref";
  366.     }
  367.     else
  368.       sErr = "badtla";
  369.   }
  370.   else
  371.     sErr = "badtla";
  372.  
  373.   if (!bOk && !this._sError)
  374.     this._sError = sErr;
  375.  
  376.   return sRet;
  377. }
  378.  
  379. // Get the name of the standard from the acronyms entry. //at
  380. CTopicInfo.prototype.GetName = function()
  381. {
  382.   //at var sRet = goDest.GetCaption();
  383.   var sRet = goLookup.GetTLA(this._oAc);
  384.  
  385.   if (sRet)
  386.     sRet = sRet.trimsp();
  387.   else
  388.     sRet = "";
  389.  
  390.   return sRet;
  391. }
  392.  
  393. // Get the TLA rid/name. //at
  394. CTopicInfo.prototype.GetTLA = function()
  395. {
  396.   var sRet = this._sTLA;
  397.  
  398.   return sRet;
  399. }
  400.  
  401. // Get appropriate ending for the standard citation sentence.
  402. CTopicInfo.prototype.GetEnd = function()
  403. {
  404.   var sRet = ". ";
  405.   var n = this._nStds;
  406.  
  407.   if (n > 2)
  408.     sRet = ", ";
  409.   else if (n == 2)
  410.   {
  411.     if (this._aStds.length > 2)
  412.       sRet = "," + sAnd;
  413.     else
  414.       sRet = sAnd;
  415.   }
  416.   else if (n == 1)
  417.     sRet = ". ";
  418.  
  419.   this._nStds--;
  420.   if (this._nStds > 0)
  421.     this._oCurStd = this._aStds[this._nStds-1];
  422.  
  423.   return sRet;
  424. }
  425.  
  426. // Get the xref rid.
  427. CTopicInfo.prototype.GetXRID = function()
  428. {
  429.   return this._sXRID;
  430. }
  431.  
  432. // Does the HREF require a leave icon?
  433. CTopicInfo.prototype.IsLeave = function(sLeave)
  434. {
  435.   var bLeave = false;
  436.  
  437.   if (goDest._leave == sLeave)
  438.     bLeave = true;
  439.  
  440.   return bLeave;
  441. }
  442.  
  443.  
  444. // CTopicData: Object encapsulating internal data for of the topic
  445. // currently being processed. //at
  446. function CTopicData(oCtx)
  447. {
  448.   this._oCtx = oCtx;
  449.   this._isValid = false;
  450.   this._error = "";
  451. }
  452.  
  453. // last error that occurred while attempting to lookup the current topic
  454. CTopicData.prototype.GetError = function()
  455. {
  456.   return this._error;
  457. }
  458.  
  459. CTopicData.prototype.IsSelf = function(sID)
  460. {
  461.   return (this._sID == sID);
  462. }
  463.  
  464. // published url to the current topic
  465. CTopicData.prototype.GetHREF = function()
  466. {
  467.   return this._oDest.GetHREF();
  468. }
  469.  
  470. // caption of the current topic
  471. CTopicData.prototype.GetCaption = function()
  472. {
  473.   return this._oDest.GetCaption();
  474. }
  475.  
  476. // Given the current topic's id, lookup the current topic in targets
  477. CTopicData.prototype.Ensure = function()
  478. {
  479.   if (this._oDest)
  480.   {
  481.     return this._isValid;
  482.   }
  483.  
  484.   this._oDest = new CLookupResults();
  485.  
  486.   var oCtx = this._oCtx;
  487.  
  488.   var oDoc = oCtx.GetDocument();
  489.   if (!oDoc)
  490.   {
  491.     this._error = "document reference unavailable in LookupLocal";
  492.     return false;
  493.   }
  494.  
  495.   var oIDAttr = oDoc.selectSingleNode("/inetsdk:topic/metadata/@id");
  496.   if (!oIDAttr)
  497.   {
  498.     this._error = "Unable to retrieve id from current topic.";
  499.     return false;
  500.   }
  501.  
  502.   this._sID = oIDAttr.value;
  503.  
  504.   // the following call will typically fail if the current topic is not
  505.   // registered in the lookup database.
  506.   if (goLookup.LookupByRID(this._sID, this._oDest, true, oCtx.GetDevLang(), "auto"))
  507.   {
  508.     this._isValid = true;
  509.     return true;
  510.   }
  511.   else if (oCtx.AllowSelfUnregistered() && goLookup.LookupLocal(null, this._oDest))
  512.   {
  513.     this._isValid = true;
  514.     return true;
  515.   }
  516.   else
  517.   {
  518.     this._error = "Current Topic Lookup: " + goLookup.GetError();
  519.     return false;
  520.   }
  521. }
  522.  
  523. ]]>
  524.